import React from 'react';
import { observer } from 'mobx-react';
import { WeaTools,WeaErrorPage,WeaSearchGroup,WeaFormItem,WeaLocaleProvider } from 'ecCom';
import { WeaSwitch } from 'comsMobx';
const getLabel = WeaLocaleProvider.getLabel;

@observer
class Condition extends React.Component{

    constructor(){
        super();
        this.fixedFormParams = {};
    }

    render(){
        let group = [];
        const { fixedCondition,fixedForm } = this.props.store;
        const fixedFormParamsTemp = fixedForm.getFormParams();
        for(let param in fixedFormParamsTemp){
            this.fixedFormParams[param] = fixedFormParamsTemp[param];
        }
        fixedForm && fixedForm.isFormInit && fixedCondition.map((v,i) =>{
            let items = [];
            v.items.map(item => {
                items.push({
                    com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@lxmbua@${item.domkey[0]}`}
                            label={`${item.label}`}
                            labelCol={{span: `${item.labelcol}`}}
                            wrapperCol={{span: `${item.fieldcol}`}}>
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@htei0m@${item.domkey[0]}`} fieldConfig={item} form={fixedForm} formParams={this.fixedFormParams} onEnterSearch={this.onEnterSearch} />
                        </WeaFormItem>),
                    colSpan:1
                });
            });
            group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@l4izjl@${i}`} needTigger={true} title={v.title} showGroup={v.defaultshow} items={items}/>);
        });
        return <div>{group}</div>
    }

    onEnterSearch = () =>{
        const { onEnterSearch } = this.props;
        onEnterSearch();
    }
}

export default WeaTools.tryCatch(React, 
    props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@vwsxh9`} msg={ props.error ? props.error : getLabel(383324,' 对不起，该页面异常，请联系管理员 ')+'！'} />,
    {error: ""}
)(Condition);